﻿#ifndef XLABELPIXMAP_H
#define XLABELPIXMAP_H

#include <QLabel>
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>

#include "xnamespace.h"

QT_BEGIN_NAMESPACE

class XLabelPixmapPrivate;
class XLabelPixmap : public QLabel
{
    Q_OBJECT

    Q_PROPERTY(QColor borderColor READ getBorderColor WRITE setBorderColor)
    Q_PROPERTY(int borderWidth READ getBorderWidth WRITE setBorderWidth)
    Q_PROPERTY(int borderRadius READ getBorderRadius WRITE setBorderRadius)
    Q_PROPERTY(QColor labelBgColor READ getLabelBgColor WRITE setLabelBgColor)

    Q_PROPERTY(QPixmap displayPixmap READ getDisplayPixmap WRITE setDisplayPixmap)
    Q_PROPERTY(bool displayEnable READ getDisplayEnable WRITE setDisplayEnable)

public:
    explicit XLabelPixmap(QWidget *parent = nullptr, Qt::WindowFlags f=Qt::WindowFlags());
    ~XLabelPixmap();

    /* Property Interface */
    QColor getBorderColor() const;
    void setBorderColor(const QColor &color);

    int getBorderWidth() const;
    void setBorderWidth(int);

    int getBorderRadius() const;
    void setBorderRadius(int);

    QColor getLabelBgColor() const;
    void setLabelBgColor(const QColor &color);

    QPixmap getDisplayPixmap() const;
    void setDisplayPixmap(QPixmap &pixmap);

    bool getDisplayEnable() const;
    void setDisplayEnable(bool);

protected:
    void paintEvent(QPaintEvent *ev) override;
    void drawBorder(QPainter *painter);
    void drawBg(QPainter *painter);

    void enterEvent(QEvent *ev) override;
    void leaveEvent(QEvent *ev) override;
    void mousePressEvent(QMouseEvent *ev) override;
    void mouseReleaseEvent(QMouseEvent *ev) override;
    void mouseMoveEvent(QMouseEvent *ev) override;

private:
    Q_DISABLE_COPY(XLabelPixmap)
    XLabelPixmapPrivate *d;
};

QT_END_NAMESPACE

#endif // XLABELPIXMAP_H
